package com.cake.liulanxiangzhu.controller;

import com.cake.liulanxiangzhu.pojo.dto.AdminBannerDTO;
import com.cake.liulanxiangzhu.pojo.dto.AdminBannerInsertDTO;
import com.cake.liulanxiangzhu.pojo.entity.AdminBanner;
import com.cake.liulanxiangzhu.pojo.vo.AdminBannerVO;
import com.cake.liulanxiangzhu.service.AdminBannerService;
import com.cake.liulanxiangzhu.web.JsonPage;
import com.cake.liulanxiangzhu.web.JsonResult;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/banner")
@Valid
public class AdminBannerController {
    @Autowired
    AdminBannerService service;

    @PostMapping("/addNew")
    public JsonResult<Void> addNew(@Valid AdminBannerInsertDTO adminBannerInsertDTO) {
        service.addNew(adminBannerInsertDTO);

        return JsonResult.ok();

    }
    /**
     *
     * <span>删除轮播图
     * @param bannerId
     * @return JsonResult< Void>
     * @author dinghao
     * @date 2023/1/14 12:20
     */
    @PostMapping("/deleteById")
    public JsonResult<Void> deleteById(Integer bannerId) {
        service.deleteByID(bannerId);
        return JsonResult.ok();
    }

    /**
     *
     * <span>03003修改轮播图数据
     * @param adminBannerDTO
     * @return void
     * @author dinghao
     * @date 2023/1/14 12:59
     */
    @PostMapping("/updateById")
    public JsonResult<Void> updateById(AdminBannerDTO adminBannerDTO){
        service.updateById(adminBannerDTO);
        return JsonResult.ok();
    }

    /**
     *
     * <span>03004查询所有轮播图数据
     * @param
     * @return List<AdminBannerVO>
     * @author dinghao
     * @date 2023/1/14 13:35
     */
    @GetMapping("/queryAllBanner")
    //@PreAuthorize("hasAuthority('weixin')")
    public JsonResult<List<AdminBannerVO>> queryALLBanner(){
        List<AdminBannerVO> adminBannerVOS = service.listBanner();
        return JsonResult.ok(adminBannerVOS);
    }
    /**
     *
     * <span>03005根据ID查询轮播图数据
     * @param
     * @return List<AdminBannerVO>
     * @author dinghao
     * @date 2023/1/14 13:35
     */
    @GetMapping("/queryBanner")
    public JsonResult<AdminBannerVO> queryBanner(Integer bannerId){
        AdminBannerVO adminBannerVO = service.queryBanner(bannerId);
        return JsonResult.ok(adminBannerVO);
    }

}
